/**
 * <p>Title: BuildBarcode</p>
 * <p>Description: the class of BuildBarcode</p>
 * <p>Copyright: Shanghai Batchsight Pharmaceutical Technologies, Inc. Copyright(c) 2016</p>
 * @author Chen Wei
 * @version 1.0
 * <pre>Histroy:
 *       2017-2-22  Chen Wei Create
 *</pre>
*/
package cn.jhg.account.util;

import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

public class BuildBarcode {
	
//	public static void main(String[] args) {
//		String str="WH170200001";
//		String i=generaterNextNumber(str);
//		System.out.println(i+"main");
//	}

	private static final String SERIAL_NUMBER = "XXyyMMXXXXX"; // 流水号格式  
	private static BuildBarcode buildBarcode = null;  
	
	private BuildBarcode() {  
	}  
	
	/** 
	 * 取得BuildBarcode的单例实现 
	 *  
	 * @return 
	 */  
	public static BuildBarcode getInstance() {  
	    if (buildBarcode == null) {  
	        synchronized (BuildBarcode.class) {  
	            if (buildBarcode == null) {  
	            	buildBarcode = new BuildBarcode();  
	            }  
	        }  
	    }  
	    return buildBarcode;  
	}  
	
	/** 
	 * 生成下一个编号 
	 */  
	public synchronized static String generaterNextNumber(String sno) {  
	    String code = null;  
	    Date date = new Date();  
	    SimpleDateFormat formatter = new SimpleDateFormat("yyMM");  
	    if (sno == null || sno.equals("")) {  
	        code = "WH"+ formatter.format(date) + "00001";  
	        System.out.println(code+"方法中");
	    } else {  
	        int count = SERIAL_NUMBER.length(); 
	        System.out.println(count);
	        StringBuilder sb = new StringBuilder();  
	        for (int i = 0; i < count; i++) {  
	            sb.append("0");  
	        }  
	        DecimalFormat df = new DecimalFormat("00000");  
	        code = "WH"+ formatter.format(date)  
	                + df.format(1 + Integer.parseInt(sno.substring(7, 11)));  
	        System.out.println(code+"方法中else");
	    }  
	    return code;  
	}  

}
